// import {
//     config,
//     refreshConfig
// } from './config.js'
import {
    response
} from './response.js'
import {
    assign
} from '@/utils/assign.js'
import axios from 'axios'
import store from '@/store'
/**@auther zhonghuanting
 * 发起请求
 */
var host='http://120.79.31.191:21000';
// var host='http://120.79.31.191:21000';
var service = axios.create({
    baseURL: host, // api的base_url  在config中分别设置开发环境和生产环境
    timeout: 60000, // request timeout
    headers: {
        'Content-Type': 'application/json; charset=UTF-8',
    }
});
service.interceptors.request.use(config => {
    config.headers['YF-JWT'] = store.getters.token.JWT;
    config.headers['PF'] = "web";
    config.headers['YF-BID'] = "zwy";
    config.headers['YF-VER'] = "1.0.0"
    config.headers['YF-UID'] = store.getters.token.user.uid
    config.params.uid = store.getters.token.user.uid || null;
    // config.params.uid = 116577 || null;
    if (config.method === 'post' || config.method === 'put' || config.method === 'delete') {
        config.data = config.params
        config.params = null;
    }
    return config;
}, error => {
    console.log(error)
})
service.interceptors.response.use(res => {
    var respones = res.data;

return	response(res,res.config)
  //  return res;
}, error => {

    return Promise.reject(error)
})


export default service
// export const request = (options) => {
//     refreshConfig();
//     options = assign(config, options)
//     return new Promise((resolve, reject) => {
//         uni.request({
//             url: config.baseUrl + options.url,
//             data: options.data,
//             header: options.header,
//             method: options.method ? options.method.toUpperCase() : 'GET',
//             success: (res) => {
//                 resolve(response(res, options))
//             }
//         });
//     })

// }


// export const requestToken = (options) => {
//     return new Promise((resolve, reject) => {
//         uni.request({
//             url: config.baseUr + options.url,
//             data: options.data,
//             header: {
//                 'content-type': 'application/json',
//                 'YF-JWT': store.getters.token.JWT,
//                 'PF': 'web',
//                 'YF-BID': 'yw',
//                 'YF-VER': '2.1.0',
//                 'YF-UID': ''
//             },
//             method: options.method ? options.method.toUpperCase() : 'GET',
//             success: (res) => {
//                 const {
//                     data,
//                     statusCode
//                 } = res
//                 if (statusCode == 200) {
//                     if (data.code == '0000') {
//                         resolve(data.data)
//                     }
//                 }
//             }
//         });
//     })

// }